var student = require("./user_model").student;
var group = require("../hackson_model").group;

var save = (req, res, tch) => {

    var student1 = new student({
        name: req.body.name1,
        studentNo: req.body.number1,
        classNo: req.body.class1
    });
    student1.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student2 = new student({
        name: req.body.name2,
        studentNo: req.body.number2,
        classNo: req.body.class2
    });
    student2.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student3 = new student({
        name: req.body.name3,
        studentNo: req.body.number3,
        classNo: req.body.class3
    });
    student3.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student4 = new student({
        name: req.body.name4,
        studentNo: req.body.number4,
        classNo: req.body.class4
    });
    student4.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student5 = new student({
        name: req.body.name5,
        studentNo: req.body.number5,
        classNo: req.body.class5
    });
    student5.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student6 = new student({
        name: req.body.name6,
        studentNo: req.body.number6,
        classNo: req.body.class6
    });
    student6.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    var student7 = new student({
        name: req.body.name7,
        studentNo: req.body.number7,
        classNo: req.body.class7
    });
    student7.save((err, resin) => {
        if (err) {
            res.send("sign in error!!!");
        } else {

        }
    });

    group.count({}, (err, number) => {
        var document = new model({
            id: number + 1,
            name: req.body.group,
            members: {
                number1: req.body.number1,
                number2: req.body.number2,
                number3: req.body.number3,
                number4: req.body.number4,
                number5: req.body.number5,
                number6: req.body.number6,
                number7: req.body.number7,
            },
            score: 0,
            voter: []
        });

        document.save((err, resin) => {
            if (err) {
                res.send("sign in error!!!");
            } else {
                res.send("sign in successfully!!! And voting entrance is not open.");
            }
        });
    })
};

module.exports = {
    save: save
};
